
<?php require_once('funciones_formulario.php'); ?>
<?php
require("./templates/comun.php");
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
	
	$destinoImagen="";
	$destinoFlash="";

	if (!empty($_POST['UpImage'])){
		$origenImagen = $_POST['UpImage'];	
		$destinoImagen=$_POST['UpImage'];
	}
	
	if (!empty($_POST['UpFlash'])){
		$origenFlash = $_POST['UpFlash'];	
		$destinoFlash ="file=".$_POST['UpFlash'];
	}

	$fecha = date("Y-m-d H:i:s");
	$conexion=Obtener_Conexion();
             //$sql="select codigo_art, equivale from invarticulos where equivale='$valorequivale'";
             //$res=pg_query($conexion,$sql)  or die ("Error linea:23 - $sql");
             //$ban=0;
	          //while($filas=pg_fetch_array($res)){

	$insertSQL = sprintf("INSERT INTO noticias (_publicado, _username, _insercion, _modificacion, Encabezado, Noticia, Imagen, Flash, Activo, FechaAlta, Idioma) VALUES ('S','anonimo','".$fecha."','".$fecha."', %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Encabezado'], "text"),
                       GetSQLValueString($_POST['Noticia'], "text"),
                       GetSQLValueString($destinoImagen, "text"),
                       GetSQLValueString($destinoFlash, "text"),
                       GetSQLValueString($_POST['Activo'], "text"),
                       GetSQLValueString($_POST['FechaAlta'], "date"),
                       GetSQLValueString($_POST['Idioma'], "text"));

  //pg_select_db($database_cnx_pizzeta, $cnx_pizzeta);
  $Result1 = pg_query($insertSQL, $conexion) or die("Error query: ".$insertSQL);
  $creado = pg_affected_rows();
  if ($creado>0){
		$update = " Update noticias set IdNoticia = ".mysql_insert_id()." where _idRegistro = ".mysql_insert_id();
		$res2= pg_query($update, $cnx_pizzeta) or die(mysql_error());
  }
  echo $creado."|".$insertSQL.$update;

}else{
?>
<table border="0" id="pag_170" cellspacing="0" cellpadding="0" style="width:100%;height:100%;" summary="Estructura">
<tr>
	<td style="vertical-align:top;">
		<div style="background-color:#84AEC9;padding:1px 1px 1px 1px;">
			<span class="EBDSTYLE_722">Formulario&nbsp;de&nbsp;Promociones - A&ntilde;adir</span>
		</div>
	</td>
</tr>
<tr>
	<td style="vertical-align:top;height:100%;background-color:#D9D9D9;border-top-color:#E6E6E6;border-top-style:solid;border-top-width:1px;border-left-color:#E6E6E6;border-left-style:solid;border-left-width:1px;border-bottom-color:#808080;border-bottom-style:solid;border-bottom-width:1px;border-right-color:#808080;border-right-style:solid;border-right-width:1px;">
	  <table align="center">
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Id:</td>
		  <td><input type="text" name="IdNoticia" id="IdNoticia" value="<?php echo $_GET['maxid']; ?>" size="32" class="formularioeditable"></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Encabezado:</td>
		  <td><input type="text" name="Encabezado" id="Encabezado" value="" size="32" class="formularioeditable"></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" valign="top" class="formularioeditable"Promocion:</td>
		  <td><textarea name="Noticia" id="Noticia" cols="50" rows="5" class="formularioeditable"></textarea>
		  </td>
		</tr>
		<tr valign="baseline">
			  <td nowrap align="right" class="formularioeditable">Codigo:</td>
			  <td>
				<input type="file" name="UpImage" id="UpImage" value="" size="32" class="formularioeditable">
				&nbsp;&nbsp;
				
			</td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Archivo tipo Flash:</td>
		  <td>
			<input type="file" name="UpFlash" id="UpFlash" value="" size="32" class="formularioeditable">
			&nbsp;&nbsp;
		</td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Activo:</td>
		  <td><select name="Activo" id="Activo" class="formularioeditable">
			<option value="N" <?php if (!(strcmp("N", ""))) {echo "SELECTED";} ?>>No</option>
			<option value="S" <?php if (!(strcmp("S", ""))) {echo "SELECTED";} ?>>Si</option>
		  </select>
		  </td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">FechaAlta:</td>
		  <td><input type="text" name="FechaAlta" id="FechaAlta" class="formularioeditable" value="" size="32"></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Idioma:</td>
		  <td>
			<?php echo ComboIdioma('Idioma',0); ?>
		  </td>
		</tr>
		<tr valign="baseline">
			<td nowrap align="right">
				<input type="button" value="Regresar" onclick="Go('list_noticias.php');return false;" class="formularioeditable">
			</td>
				
			<td>
				<input type="button" value="Grabar"  onclick="fnsubmitNoticiasInsert();return false;" class="formularioeditable">
			</td>
		</tr>
	  </table>
	<input type="hidden" name="MM_insert" value="form1">
	</td>
</tr>
</table>
<p>&nbsp;</p>

<?php } ?>